<extend name="Base/common"/>
<block name="TITLE"><title>世果代购</title></block>
<block name="body">   
            <div>
            <img src="__IMG__/sgdg.jpg" class="am-margin-0" style="width:100%;" />
        </div>
    <hr/>
    <div class="am-container am-margin-top-0" >

        <form class="am-form "  id="agentform"  action="{:U('Agent/saveAgent')}" enctype="multipart/form-data" method="post">
            <div style="margin-top: 10px;">  
                
            </div>
            <div class="am-form-group " style="display: inline;">
                <label for="username" class="am-form-label lable_font" ><i class="am-icon-list"></i>&nbsp;代购商品列表</label>
                    <div class="am-list am-g">
                        <div class="am-u-sm-6">
                        <input type="text" name='agent_name[]' class="am-form-field agent_names" placeholder="代购商品名" >
                        </div>
                        <div class='am-u-sm-2 am-padding-top-xs am-padding-left-0 am-padding-right-0'>
                            <span  class=" agent_price " style='color:red;font-weight: 700;'></span>
                             <input type='hidden' name='agent_price[]' class='agent_prices'>
                        </div>
                        <div class="am-u-sm-4">
                        <input type="text" name='agent_num[]' class="am-form-field agent_good_nums" placeholder="数量(例:10斤)" >
                        </div>
                    </div>
                  <button type="button" class="am-btn am-btn-primary am-radius agent_num am-margin-left-sm">增加商品</button> 
            </div>
              
            <div class="am-form-group am-margin-top-sm" style='clear: both;' >                
                    <label for="describe" class="am-form-label lable_font"> <i class="am-icon-file"></i> &nbsp;备注</label>
                    <textarea class=" am-radius " rows="3" id="describe" name="describe"  placeholder="对于您的代购，我们还该注意哪些"></textarea>  
            </div>
            
            <div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
                                <div class="am-modal-dialog">
                                  <div class="am-modal-hd">温馨提示</div>
                                  <div class="am-modal-bd">
                                    您的个人信息不完整
                                  </div>
                                  <div class="am-modal-footer">
                                    <span class="am-modal-btn">确定</span>
                                  </div>
                                </div>
           </div>
            
            <div class="am-modal am-modal-alert" tabindex="-1" id="my-alert2">
                                <div class="am-modal-dialog">
                                  <div class="am-modal-hd">温馨提示</div>
                                  <div class="am-modal-bd">
                                    请至少输入一种商品
                                  </div>
                                  <div class="am-modal-footer">
                                    <span class="am-modal-btn">确定</span>
                                  </div>
                                </div>
           </div>
            <div class="am-modal am-modal-alert" tabindex="-1" id="my-alert3">
                                <div class="am-modal-dialog">
                                  <div class="am-modal-hd">温馨提示</div>
                                  <div class="am-modal-bd">
                                    请正确输入数量+<d style='color:red;'>规格</d>(例:1<d style='color:red'>箱</d>、20<d style='color:red'>斤</d>等)
                                  </div>
                                  <div class="am-modal-footer">
                                    <span class="am-modal-btn">确定</span>
                                  </div>
                                </div>
           </div>
            
        <div class="am-modal am-modal-prompt" tabindex="-1" id="my-prompt-3">
            <div class="am-modal-dialog">
                <div class="am-modal-hd lable_font">请确认收货地址</div>
                <div class="am-modal-bd">
                    <div class="am-form-group ">                
                    <label for="username" class="am-form-label " ><i class="am-icon-user"></i>&nbsp;用户姓名</label>
                     <input type="text" id="username" name="username" class="am-form-field am-radius"  value='{$realname}'  required>                    
                    </div>
                    <div class="am-form-group " >                
                        <label for="usertel" class=" am-form-label "><i class="am-icon-phone"></i>&nbsp;联系方式</label>
                        <input type="text" id="usertel" name="usertel" class="am-form-field am-radius js-pattern-mobile" value='{$phone}'  >                    
                    </div>
                    <div class="am-form-group " >                
                        <label for="usertel" class=" am-form-label "><i class="am-icon-home"></i>&nbsp;商铺地址</label>
                        <input type="text" id="usertel" name="useraddr" class="am-form-field am-radius js-pattern-mobile" value='{$addr}'  >                    
                    </div>
                </div>
                <div class="am-modal-footer">
                    <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                    <!--<span class="am-modal-btn confirm-submit" data-am-modal-confirm>确认提交</span>-->
                    <input type="submit" class="am-text-secondary confirm-submit" style="background: none;border: none;"  value="确认提交"/>
                </div>
            </div>
        </div>
            
            
<p style='text-align: center'><input type="button" id="submit" class="am-btn am-btn-secondary am-radius" style="color:#FFF;" value="提交申请"></p>
        </form>
    </div>
</block>
<block name="script">
    <script>
         $('.confirm-submit').click(function(){
            var username = $('#username').val();
            var usertel = $('#usertel').val();
            var useraddr = $('#useraddr').val();    
            if(usertel==""||useraddr==""||username==""){
                      window.alert("你的收货信息不完整");
                     return false;   
            }
         });
         $('.agent_num').click(function(){
             $(this).before("<div class='am-list am-g'><div class='am-u-sm-6'><input type='text' class='am-form-field agent_names' name='agent_name[]' placeholder='代购商品名'></div><div class='am-u-sm-2 am-padding-top-xs'><span name='agent_price[]' class='agent_price am-padding-left-0 am-padding-right-0' style='color:red;font-weight: 700;'></span><input type='hidden' name='agent_price[]' class='agent_prices'></div><div class='am-u-sm-4'><input type='text' class='am-form-field agent_good_nums' name='agent_num[]' placeholder='数量(例:10斤)'></div></div>");
             $('.agent_good_nums').bind('change', function() {
                    if(isNaN($(this).val())){

                    }else{
                         $('#my-alert3').modal({
                                   relatedTarget: $(this),
                                   onConfirm: function (e) {
                                   return false;
                                   }
                         });
                       };
                    });   
             $('.agent_names').bind('change',function(){
                    var goods_input=$(this);
                    var goods_name=$(this).val();
                    $.post('__URL__/ajax',{pname:goods_name},function(msg){
                        if(msg==""||msg==null){  
                        }else{
                            goods_input.parent().next().children("span").html('￥'+msg);
                            goods_input.parent().next().children("input").val(msg);
                        }
                      });
                      });
              });
         $('.agent_good_nums').change(function(){
             if(isNaN($(this).val())){
                
             }else{
                  $('#my-alert3').modal({
                            relatedTarget: $(this),
                            onConfirm: function (e) {
                            return false;
                            }
                  });
             };
         });
         
        $('.agent_names').change(function(){
             var goods_input=$(this);
             var goods_name=$(this).val();
             $.post('__URL__/ajax',{pname:goods_name},function(msg){
                 if(msg==""||msg==null){  
                 }else{
                     goods_input.parent().next().children("span").html('￥'+msg);
                     goods_input.parent().next().children("input").val(msg);
                 }
               });

             
        });
         
        $('#submit').click(function(){
            var name='';
            $('.agent_names').each(function(){
                name=name+$(this).val();
            });
            if(name==""||name==null||name==undefined){
                     $('#my-alert2').modal({
                            relatedTarget: $(this),
                            onConfirm: function (e) {
                            return false;
                            }
                      });
                 return false;       
            }else{
                    $('#my-prompt-3').modal({
                            relatedTarget: $(this),
                            onCancel: function () {
                                 return false;
                            }
                    });
                 
            }     
          
        });
    </script>      
</block>